<?php
require_once 'Zend/Controller/Plugin/Abstract.php';

class Custom_Controller_Plugin_Output extends Zend_Controller_Plugin_Abstract
{
	/**
	 * 输出消息框
	 * 
	 * @param string 输出消息
	 * @param bool 状态(true为success，false为failure)
	 * 
	 */
	public function success($state = true, $text = null)
	{
		$data = array();
		$data['success'] = $state;
		$data['message'] = $text;
		
		$this->display(json_encode($data,JSON_HEX_TAG));
		
		return $state;
	}
	
	/**
	 * 输出LOAD数据
	 *
	 * @param array 要返回的数据
	 */
	public function load($data)
	{
		$json = array();
		$json['success'] = true;
		$json['data'] = $data;
		$this->display(json_encode($json, JSON_HEX_TAG));
	}
	
	/**
	 * 输出grid数据
	 * 
	 * @param array 记录集
	 */
	public function grid($rows)
	{
		$data = array();
		$data['total'] = count($rows);
		$data['rows'] = $rows;
		$data = json_encode($data, JSON_HEX_TAG);
		$this->display($data);
	}
	
	/**
	 * 输出记录集
	 * 
	 * @param array $data
	 */
	public function rows($data)
	{
		$this->display(json_encode($data, JSON_HEX_TAG));
	}
	
	
	/**
	 * 系统输出
	 * 
	 * @param string $data 输出消息
	 */
	public function display($data = null)
	{
		header("Content-type:text/html; charset=utf-8");
		print_r($data);
	}
}